package com.jbm.enterapplication.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;

/**
 * 微信支付
 * @author inspiry_pc
 *
 */
public class WXPayEntryActivity extends Activity implements
		IWXAPIEventHandler {
	private IWXAPI api;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.pay_result);
//		api = WXAPIFactory.createWXAPI(this, Constant.WX_APP_ID);
		api.handleIntent(getIntent(), this);
//		api.handleIntent(getIntent(), this);
//		ExitAppUtils.getInstance().addActivity(WXPayEntryActivity.this);
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
//		MyToast.show(WXPayEntryActivity.this, "支付取消！"+req.openId, 0);
	}

	@Override
	public void onResp(BaseResp resp) {
		//Resp.errstr : 0 支付成功 -1 不成功 -2 取消支付。
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
			Intent intent = new Intent("pay");
			if (resp.errCode == BaseResp.ErrCode.ERR_OK) {
//				MyToast.show(WXPayEntryActivity.this, "支付成功！", 0);
				intent.putExtra("success",true);
			} else{
				intent.putExtra("success",false);
//				MyToast.show(WXPayEntryActivity.this, "支付失败！", 0);
			}
			sendBroadcast(intent);
			finish();
		}
	}
}